package com.sandalphon4869.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

public class PIMCollection implements Collection<PIMEntity>{
	
	public ArrayList<PIMEntity> myCollection = new ArrayList<>();
	
	public Collection getNotes() {
		Collection collection = new ArrayList<PIMNote>();
		for(int i = 0 ; i < this.size() ; i++)
		{
			PIMEntity entity = myCollection.get(i);
			if(entity.getClass().getSimpleName().equals("PIMNote"))
			{
				collection.add(entity);
			}
		}
		return collection;
	}
	
	public Collection getTodos() {
		Collection collection = new ArrayList<PIMTodo>();
		for(int i = 0 ; i < this.size() ; i++)
		{
			PIMEntity entity = myCollection.get(i);
			if(entity.getClass().getSimpleName().equals("PIMTodo"))
			{
				collection.add(entity);
			}
		}
		return collection;
	}
	
	public Collection getAppointments() {
		Collection collection = new ArrayList<PIMAppointment>();
		for(int i = 0 ; i < this.size() ; i++)
		{
			PIMEntity entity = myCollection.get(i);
			if(entity.getClass().getSimpleName().equals("PIMAppointment"))
			{
				collection.add(entity);
			}
		}
		return collection;
	}
	
	public Collection getContact() {
		Collection collection = new ArrayList<PIMContact>();
		for(int i = 0 ; i < this.size() ; i++)
		{
			PIMEntity entity = myCollection.get(i);
			if(entity.getClass().getSimpleName().equals("PIMContact"))
			{
				collection.add(entity);
			}
		}
		return collection;
	}
	
	public Collection getItemsForDate(Date d) {
		int month = d.getMonth() + 1;
		int dayOfMonth = d.getDate();
		int year = d.getYear() + 1900;
		String date = "" + month + "/" + dayOfMonth + "/" + year;
		System.out.println("in get"+date);
		Collection collection = new ArrayList<PIMEntity>();
		for(int i = 0 ; i < this.size() ; i++)
		{
			PIMEntity entity = myCollection.get(i);
			switch(entity.getClass().getSimpleName())
			{
			case "PIMTodo":
			{
				PIMTodo todo =(PIMTodo)entity;
				if(todo.getDate().equals(date))
				{
					collection.add(entity);
				}
				break;
			}
			case "PIMAppointment":
			{
				PIMAppointment appointment =(PIMAppointment)entity;
				if(appointment.getDate().equals(date))
				{
					collection.add(entity);
				}
				break;
			}
			default :
			{
				break;
			}
			}
		}
		return collection;
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return myCollection.size();
	}

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return myCollection.isEmpty();
	}

	@Override
	public boolean contains(Object o) {
		// TODO Auto-generated method stub
		return myCollection.contains(o);
	}

	@Override
	public Iterator<PIMEntity> iterator() {
		// TODO Auto-generated method stub
		return myCollection.iterator();
	}

	@Override
	public Object[] toArray() {
		// TODO Auto-generated method stub
		return myCollection.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a) {
		// TODO Auto-generated method stub
		return myCollection.toArray(a);
	}

	@Override
	public boolean add(PIMEntity e) {
		// TODO Auto-generated method stub
		return myCollection.add(e);
	}

	@Override
	public boolean remove(Object o) {
		// TODO Auto-generated method stub
		return myCollection.remove(o);
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		// TODO Auto-generated method stub
		return myCollection.containsAll(c);
	}

	@Override
	public boolean addAll(Collection<? extends PIMEntity> c) {
		// TODO Auto-generated method stub
		return myCollection.addAll(c);
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		// TODO Auto-generated method stub
		return myCollection.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		// TODO Auto-generated method stub
		return myCollection.retainAll(c);
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		myCollection.clear();
	}
}
